import {PrismaAdapter} from "@auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import NextAuth,{NextAuthOptions,User as NextAuthUser} from "next-auth";
import GitHubProvider from "next-auth/providers/github"

interface NextAuthUserWithStringId extends NextAuthUser{
    id:string
}

const prisma = new PrismaClient();

export const authOptions:NextAuthOptions={
    adapter:PrismaAdapter(prisma),
    providers: [
        GitHubProvider({
            clientId:process.env.GITHUB_ID!,
            clientSecret:process.env.GITHUB_SECRET!,
            profile(profile) {
                return {
                    id: profile.id.toString(),
                    name: profile.name || profile.login,
                    email: profile.email,
                    image: profile.avatar_url,
                } as NextAuthUserWithStringId
            },
        })
    ],
    session:{
        strategy:"jwt"
    },

}

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };